//
//  SLTabBarController.m
//  SoccerLottery
//
//  Created by chuanshuangzhang chuan shuang on 15/12/24.
//  Copyright © 2015年 chuanshuangzhang. All rights reserved.
//

#import "SLTabBarController.h"
#import "SLSettingViewController.h"
#import "SLLoginViewController.h"

@interface SLTabBarController ()<UIAlertViewDelegate>

@property (nonatomic,strong) UISegmentedControl *segmentControl;

@end

@implementation SLTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitle:@"竞彩足球" back:NO];
    [self setRightItem:nil imageName:@"setting"];
    _segmentControl = [[UISegmentedControl alloc]initWithItems:@[@"免费推介",@"心水推介"]];
    _segmentControl.frame = CGRectMake(20.0, 5, App_Frame_Width-40, 40.0);
    _segmentControl.selectedSegmentIndex = 0;
    _segmentControl.tintColor = RGBACOLOR(236, 73,93, 1.0);
    [self.tabBar addSubview:_segmentControl];
    [_segmentControl addTarget:self action:@selector(segmentValueChanged:) forControlEvents:UIControlEventValueChanged];
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if([[UserModel sharedInstance].userId integerValue]<1){
        [self setRightItem:@"" imageName:nil];
    }else {
        [self setRightItem:nil imageName:@"setting"];
    }
}
- (void)segmentValueChanged:(UISegmentedControl *)segmentControl
{
    [self setSelectedIndex:segmentControl.selectedSegmentIndex];

//    if(segmentControl.selectedSegmentIndex == 1 && [[UserModel sharedInstance].userId integerValue]<1){
//#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000
//        UIAlertView *alterView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"心水推介文章只对注册用户开放"delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"去登录", nil];
//        [alterView show];
//#else
//        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
//        UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"去登录" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//            [self openLogin];
//        }];
//        UIAlertController *control = [UIAlertController alertControllerWithTitle:@"提示" message:@"心水推介文章只对注册用户开放" preferredStyle:UIAlertControllerStyleAlert];
//        [control addAction:cancelAction];
//        [control addAction:okAction];
//        [self presentViewController:control animated:YES completion:nil];
//#endif
//        [segmentControl setSelectedSegmentIndex:0];
//        return;
//    }
    
}

- (void)openLogin
{
 
}
- (void)rightBarButtonItemAction:(id)sender
{
    SLSettingViewController *vc = [[SLSettingViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
